<div class="modal fade" id="pay-dlg">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" style="line-height: 30px;font-size: 16px;">
                    确认订单
                    <i data-dismiss="modal" class="iconfont icon-guanbi"
                       style="float: right;font-size: 26px;cursor: pointer"></i>
                    <span class="express_no"></span>
                </h4>
            </div>
            <form method="post" action="{{route('web.cart.pay')}}" id="orderToPay">
                <div class="modal-body">
                    {{csrf_field()}}
                    <input type="hidden" class="product_ids" name="product_ids" value="">
                    <input type="hidden" class="product_nos" name="product_nos" value="">
                    <input type="hidden" class="buy_nums" name="buy_nums" value="">

                    <?php
                    $user_addr = \App\Models\MAddress::where("uid", ss('uid'))->first();
                    $user = \App\Models\MUser::find(ss('uid'));
                    ?>
                    <div class="row input-row" style="padding-right: 15px;">
                        <div class="col-xs-offset-1">
                            <label class="col-xs-12 title" style="font-size: 15px;">
                                收货地址 - Safe Password
                            </label>
                        </div>
                        <div class="col-md-6 col-xs-12 col-xs-offset-1">
                            <div class="input-group" style="width: 100%;">
                                @if(isset($user_addr))
                                    <span>{{uAddrStr($user_addr->uid)}}</span><br>
                                    <span>收货人：{{$user_addr->name or ''}}</span>&nbsp;
                                    <span>{{$user_addr->tel}}</span>&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href="{{route('web.address')}}" style="color: red;">修改收货地址</a>
                                @else
                                    <a href="{{route('web.address')}}" style="color: red;">添加收货地址</a>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-5 col-xs-12">
                            <label class="label-intro">
                            </label>
                        </div>
                    </div>
                    <br>
                    <div class="row input-row" style="padding-right: 15px;">
                        <div class="col-xs-offset-1">
                            <label class="col-xs-12 title" style="font-size: 15px;">
                                应付金额 - Pay Money<br><span id="payMoney"
                                                          style="color: red;margin-right: 15px;">￥ <span>100.00</span></span>
                                <input type="hidden" class="payMoney" name="payMoney">
                            </label>
                        </div>
                        <div class="col-md-6 col-xs-12 col-xs-offset-1">
                            <div class="input-group" style="width: 100%">

                                <input id="payMoney" name="payMoney" readonly type="hidden"
                                       class="form-control">
                                <select class="wallet form-control" id="wallet" name="wallet">
                                    <option value="">
                                        --请选择支付钱包--
                                    </option>
                                    <option value="{{\App\Models\MWallet::$WALLET_TYPE_1}}">
                                        {{uWalletStr(\App\Models\MWallet::$WALLET_TYPE_1)}}（{{$user->wallet->w1 }}）
                                    </option>
                                    <option value="{{\App\Models\MWallet::$WALLET_TYPE_2}}">
                                        {{uWalletStr(\App\Models\MWallet::$WALLET_TYPE_2)}}（{{ $user->wallet->w2 }}）
                                    </option>
                                    <option value="{{\App\Models\MWallet::$WALLET_TYPE_3}}">
                                        {{uWalletStr(\App\Models\MWallet::$WALLET_TYPE_3)}}（{{ $user->wallet->w3 }}）
                                    </option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-5 col-xs-12">
                            <label class="label-intro" for="wallet">
                            </label>
                        </div>
                    </div>
                    <br>
                    <div class="row input-row" style="padding-right: 15px;">
                        <div class="col-xs-offset-1">
                            <label class="col-xs-12 title" style="font-size: 15px;">
                                交易密码 - Safe Pass
                            </label>
                        </div>
                        <div class="col-md-6 col-xs-12 col-xs-offset-1">
                            <div class="input-group" style="width: 100%">

                                <input id="safepass" name="safepass" type="password"
                                       class="form-control">
                            </div>
                        </div>
                        <div class="col-md-5 col-xs-12">
                            <label class="label-intro" for="safepass">
                            </label>
                        </div>
                    </div>
                    <br>
                    <div class="row input-row" style="padding-right: 15px;">
                        <div class="col-xs-offset-1">
                            <label class="col-xs-12 title" style="font-size: 15px;">
                                订单备注 - Order Remarks
                            </label>
                        </div>
                        <div class="col-md-6 col-xs-12 col-xs-offset-1">
                            <div class="input-group" style="width: 100%">
                                <textarea id="detail" name="detail" class="form-control"></textarea>
                            </div>
                        </div>
                        <div class="col-md-5 col-xs-12">
                            <label class="label-intro" for="detail">
                            </label>
                        </div>
                    </div>
                    <br>

                </div>
                <div class="modal-footer">
                    <button type="submit" id="toPay" class="btn btn-primary">立即支付</button>
                    <a href="#" id="cancel-pro" class="btn btn-default" data-dismiss="modal">关闭</a>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script type="text/javascript">
    //获取物流数据并加入到模态框
    function payDlg() {
        var total = $("input[name='payMoney']").val();
//        $.post("express-info/" + oid, function (data) {
        if (total <= 0 || total == '') {
            toastr["error"]('请选择您要购买的商品');
            return false;
        } else {
            $("#pay-dlg").modal();
        }

//        })
    }

    // 验证规则
    $('#orderToPay').validate({
        rules: {
            wallet: {
                required: true
            },
            safepass: {
                required: true
            }
        }, errorPlacement: function (error, element) {
            $(element).closest("form").find("label[for='" + element.attr("id") + "']").html(error);
        },
//        remote: {
//            url: "",     //后台处理程序
//            type: "post",               //数据发送方式
//            dataType: "json",           //接受数据格式
//            data: {                     //要传递的数据
//                password: function () {
//                    return $("#password").val();
//                }
//            }
//        },
        submitHandler: function (form) {
            $(form).ajaxSubmit({
                dataType: "json",
                type: "post",
                beforeSend: function () {
                    //禁用按钮,防止重复提交
                    $("#toPay").attr('disabled', 'disabled')
                },
                success: function (data) {
                    if (data.code == 0) {
                        toastr["success"](data.msg);
                        setInterval(function () {
                            window.location.reload();
                        }, 2000);
                    } else {
                        $("#toPay").removeAttr('disabled');
                        toastr["error"](data.msg);
                    }
                }
            });
        }
    });
</script>